package org.stvd.service.oauth;

import java.util.Map;

import org.springframework.security.oauth2.common.util.OAuth2Utils;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.OAuth2Request;
import org.springframework.security.oauth2.provider.TokenRequest;
import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; 

/*
 * 验证客户端信息
 */
public class CustomOAuth2RequestFactory extends DefaultOAuth2RequestFactory {

    public CustomOAuth2RequestFactory(ClientDetailsService clientDetailsService) {
        super(clientDetailsService);
    }

    @Override
    public AuthorizationRequest createAuthorizationRequest(Map<String, String> authorizationParameters) {
        //处理地址栏手动输入oauth/authorize时client_id丢失导致查询时缓存报错的问题
        if(!authorizationParameters.containsKey(OAuth2Utils.CLIENT_ID)) {
            authorizationParameters.put(OAuth2Utils.CLIENT_ID, "");
        }
        return super.createAuthorizationRequest(authorizationParameters);
    }

    @Override
    public OAuth2Request createOAuth2Request(AuthorizationRequest request) {
        // TODO Auto-generated method stub
        return super.createOAuth2Request(request);
    }

    @Override
    public TokenRequest createTokenRequest(Map<String, String> requestParameters, ClientDetails authenticatedClient) {
        // TODO Auto-generated method stub
        return super.createTokenRequest(requestParameters, authenticatedClient);
    }

    @Override
    public TokenRequest createTokenRequest(AuthorizationRequest authorizationRequest, String grantType) {
        // TODO Auto-generated method stub
        return super.createTokenRequest(authorizationRequest, grantType);
    }

    @Override
    public OAuth2Request createOAuth2Request(ClientDetails client, TokenRequest tokenRequest) {
        // TODO Auto-generated method stub
        return super.createOAuth2Request(client, tokenRequest);
    }


}
